package com.totalinlink.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import android.widget.RelativeLayout;
import android.widget.TextView;

import com.totalinlink.sisclient.MainActivity;
import com.totalinlink.sisclient.R;

/**
 * Created by zhangpf1127 on 2015/9/6.
 */

public class MenuFragment extends Fragment implements OnClickListener {

    private final Context context;

    public MenuFragment(Context context) {
        this.context = context;
    }

    private RelativeLayout menuLogin;
    private RelativeLayout menuHome;
    private RelativeLayout menuMine;
    private RelativeLayout menuAbout;
    private TextView tvUsername;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        View view=inflater.inflate(R.layout.menufragment_white, container,false);

        tvUsername = (TextView)view.findViewById(R.id.user_name);
        menuLogin = (RelativeLayout)view.findViewById(R.id.menu_login);
        menuHome = (RelativeLayout)view.findViewById(R.id.menu_home);
        menuMine = (RelativeLayout)view.findViewById(R.id.menu_mine);
        menuAbout = (RelativeLayout)view.findViewById(R.id.menu_about);
        menuLogin.setOnClickListener(this);
        menuHome.setOnClickListener(this);
        menuMine.setOnClickListener(this);
        menuAbout.setOnClickListener(this);
        return view;
    }

    @Override
    public void onClick(View view) {
        // TODO Auto-generated method stub
        Fragment newContent = null;
        switch (view.getId()) {
            case R.id.menu_login:
                newContent = new LoginFragment(context);
                break;
            case R.id.menu_home:
                newContent = new HomeFragment();
                break;
            case R.id.menu_mine:
                newContent = new MineFragment();
                break;
            case R.id.menu_about:
                newContent = new AboutFragment();
                break;
            default:
                break;
        }
        if (newContent != null)
            switchFragment(newContent);
    }

    private void switchFragment(Fragment fragment) {
        if (getActivity() == null) {
            return;
        } else {
            MainActivity ra = (MainActivity) getActivity();
            ra.switchContent(fragment);
        }
    }
}
